using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    public class MRPGroupsService
    {
        ISession session;

        public MRPGroupsService(ISession session)
        {
            this.session = session;
        }
        public MRPGroupsService()
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpgroups(MRPGroups mrpgroupsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpgroupsX);
            tx.Commit();
        }

        public void UpdateMrpgroups(MRPGroups mrpgroupsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpgroupsX);
            tx.Commit();
        }

        public void DeleteMrpgroups(MRPGroups mrpgroupsX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpgroupsX);
            tx.Commit();
        }

        public IList<MRPGroups> GetAllMrpgroups(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPGroups");
            IList<MRPGroups> list = query.List<MRPGroups>();
            if (evict)
            {
                foreach (MRPGroups s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPGroups GetAllMrpgroupsByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPGroups as c where c.Groupcode= :x");
            query.SetString("x", id);
            MRPGroups s = (MRPGroups)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPGroups> GetMrpgroupsByQuery(IQuery query, Boolean evict)
        {
            IList<MRPGroups> list = query.List<MRPGroups>();
            if (evict)
            {
                foreach (MRPGroups s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

    }
}
